﻿
function GetUserLogin()
{
    $.ajax({
        type: "GET",
        url: "/api/User/ShowUserLogin",
        contentType: 'application/json',
        beforeSend: function ()
        {
            $("#BT_Login").text("处理中...");
        },
        error: function (xmlHttpRequest, textStatus, errorThrown)
        {
            alert(xmlHttpRequest.statusText);

        },
        success: function (info)
        {
            if (info.Logined == false)
            {
                $("#UserLoginedUI").hide();
                $("#UserLoginUI").show();
            }
            else
            {
                if ($("#UserLoginUI").length > 0 && $("#UserLoginedUI").length > 0)
                {
                    $("#UserLoginUI").hide();
                    $("#UserLoginedUI").show();

                    $("#UserLoginedUI_Name").text(info.Name);
                    $("#UserLoginedUI_PetName").text(info.PetName);
                    $("#UserLoginedUI_Coin").text(info.Coin);
                    $("#UserLoginedUI_Point").text(info.Point);
                    $("#UserLoginedUI_ActiveType").text(info.ActiveType);
                    $("#UserLoginedUI_RoleName").text(info.RoleName);


                    $("#UserLoginedUI_Money").text(info.Money);
                    $("#UserLoginedUI_Score").text(info.Score);
                    $("#UserLoginedUI_Discount").text(info.Discount);
                }
            }

        }
    });
}


function UserLogout()
{
    $.ajax({
        type: "post",
        contentType: 'application/json',
        url: "/api/User/Logout",
        beforeSend: function ()
        {
        },
        success: function (info)
        {
            window.location = window.location; //注销成功以后刷新网页。
        }
    });
}

function PostLogin()
{
    var u = $("#UserName").val();
    var w = $("#UserPSW").val();
    var p = $("#PassCode").val();
    var k = $("#KeepLong").val();

    if (u == "")
    {
        alert("请输入用户名");
        return;
    }
    if (w == "")
    {
        alert("请输入密码");
        return;
    }


    var parameters = "UserName=" + escape(u);
    parameters += "&UserPSW=" + escape(w);
    parameters += "&PassCode=" + p;
    parameters += "&KeepLong=" + k;

    $.ajax({
        type: "POST",
        url: "/api/User/Login",
        contentType: 'application/json',
        data: parameters,
        dataType: "json",
        beforeSend: function ()
        {
            $("#BT_Login").val("处理中...");
        },
        error: function (msg)
        {
            alert("post 登录出错。");
        },
        success: function (result)
        {
            if (result.Err != "")
            {
                alert(result.Err);
            }
            GetUserLogin();
        }
    });
}

 

$(function ()
{
    GetUserLogin();
});